
/* 
这是一个基于 LXLRobot 机器人插件的 扩展功能
包括正则,和群成员绑定和群互通聊天
版本v0.0.8
*/
const versions = "0.0.8 已支持 自定义接口解析 功能强大";
let config = YoyoClass.JsonConfig(".\\regular\\config.json", data.toJson({
    group: ["569211842"],//监听群
    adminList: ["1294858802"],//管理员
    serverName: "生存服",
    AddGroupAgreed: {//是否开启申请加群自动同意
        blacklist: [
        ]

    },
    functionSwitch: {
        InAndOutOfTip: true,//进入提示开关
        ChatForward: true,//聊天转发开关
        AddGroupAgreed: true//加入同意开关
    },
    stray: [//成员离群自动解绑的 和 触发以下指令
        { type: "group", msg: "[{user.name}]这个家伙已经离开群了" },
        { type: "cmd", cmd: "whitelist remove \"{bind.name}\"" }
    ],
    regular: [
        { type: "group", se: "^在线玩家$", cmd: "list", result: "There are ([\\d/]+) players online:([\\s\\S]*)", msg: "当前玩家$1:$2", op: 0 },//自带匹配返回格式
        { type: "group", se: "^/(.+)$", cmd: "$1", msg: "[命令] $1 已发送", op: 1 },//返回一个提示
        { type: "group", se: "^清理掉落物$", cmd: "kill @e[type=item]", op: 1 },//不带返回
        { type: "group", se: "^绑定 ([\\da-zA-Z ]+)$", msg: "$1", fun: "bind", op: 0 },//调用方法绑定游戏名
        { type: "group", se: "^解绑 ([\\da-zA-Z ]+)$", msg: "$1", fun: "unbind", op: 1 },//调用方法解除绑定游戏名
        { type: "group", se: "^服务器状态$", msg: "物理内存:{ram}/{tram}", fun: "serverInfo", op: 0 },//调用方法
        { type: "group", se: "^%(.+)", msg: "§l[§e{group.name}§r§l]<{user.name}>$1", fun: "tellAll", op: 0 },
        { type: "group", se: "^转账\\s?@(\\d{5,10})\\s(\\d{1,10})$", msg: "[钱]成功为 {bind.name} 转账 $2 大洋!", fun: "transfer", op: 0 },//转账
        { type: "group", se: "^扣钱\\s?@(\\d{5,10})\\s(\\d{1,10})$", msg: "[钱]成功为 {bind.name} 扣除 $2 大洋!", fun: "DeductMoney", op: 1 },//扣钱
        { type: "group", se: "^加钱\\s?@(\\d{5,10})\\s(\\d{1,10})$", msg: "[钱]成功为 {bind.name} 增加 $2 大洋!", fun: "AddMoney", op: 1 },//加钱
        { type: "group", se: "^余额$", msg: "[钱]{bind.name} 你当前 余额是 {llmoney} 大洋!", fun: "TheBalanceOf", op: 0 },//余额
        { type: "group", se: "^美女$", msg: "belle", fun: "url", op: 0 },// url请求解析美女
        { type: "group", se: "^动漫$", msg: "dm", fun: "url", op: 0 },// url请求解析动漫
        { type: "group", se: "^ping\\s?([\\.\\w]+)$", msg: "ping", fun: "url", op: 0 },// url请求解析
        { type: "cmd", se: "Player added to whitelist", msg: "白名单添加完成" },//抓取控制台命令执行结果
        { type: "cmd", se: "Player already in whitelist", msg: "你已经在白名单里面了" },
        { type: "cmd", se: "Player removed from whitelist", msg: "成功移除白名单" },
        { type: "cmd", se: "Player not in whitelist", msg: "玩家未在白名单里面" }
    ]
}));

// RobotApiClass.sendGroupMsg(569211842,"我是机器人扩展,我被加载了");
let bindConfig = YoyoClass.JsonConfig(".\\regular\\bind.json", data.toJson({
    bind: {
    }
}));

let urlConfig = YoyoClass.JsonConfig(".\\regular\\url.json", data.toJson({
    ping:{
        url:"https://api.gmit.vip/Api/Ping",
        method:"post",
        data:"format=json&ip=$1&node=0",
        return:{
            data:[
                {msg:"平均延迟:",type:"text"},
                {path:"data.ping_avg",type:"text"}
            ]
        }
    }
}));

let funs = {
    /**
     * 查询余额
     * @param {string} xuid 玩家xuid
     */
    TheBalanceOf(xuid, msg, group) {
        let MyMoney = money.get(xuid);
        msg = msg.replace(/{llmoney}/g, MyMoney);
        RobotApiClass.sendGroupMsg(group, `[${config.get("serverName")}]${msg}`);
    },
    /**
     * 增加指定玩家的金额
     * @param {string} xuid 加钱玩家的xuid
     * @param {number} money 金额
     * @param {string} msg 预定信息
     * @returns 
     */
    AddMoney(xuid, money2, msg, group) {
        let result = money.add(xuid, money2);
        if (!result) {
            RobotApiClass.sendGroupMsg(group, `[${config.get("serverName")}]添加金额失败!`);
            return false;
        }
        RobotApiClass.sendGroupMsg(group, `[${config.get("serverName")}]${msg}`);
    },
    /**
     * 扣除指定玩家的金额
     * @param {string} xuid 扣款玩家的xuid
     * @param {number} money 金额
     * @param {string} msg 预定信息
     * @returns 
     */
    DeductMoney(xuid, money2, msg, group) {
        let result = money.reduce(xuid, money2);
        if (!result) {
            RobotApiClass.sendGroupMsg(group, `[${config.get("serverName")}]扣除金额失败!`);
            return false;
        }
        RobotApiClass.sendGroupMsg(group, `[${config.get("serverName")}]${msg}`);
    },
    /**
     * 向指定玩家转账
     * @param {string} xuid1 付款玩家xuid
     * @param {string} xuid2 收款玩家xuid
     * @param {number} money 转账的金额
     * @param {string} msg 预定的信息
     */
    transfer(xuid1, xuid2, money2, msg, group) {
        let result = money.trans(xuid1, xuid2, money2);
        if (!result) {
            RobotApiClass.sendGroupMsg(group, `[${config.get("serverName")}]发起转账失败!`);
            return false;
        }
        RobotApiClass.sendGroupMsg(group, `[${config.get("serverName")}]${msg}`);

    },
    /**
     * 向服务器所有在线玩家广播信息
     * @param {string} msg 消息
     */
    tellAll(msg) {
        mc.broadcast(msg);
    },
    /**
     * 查询服务器状态
     * @param {string} msg 头部预定信息
     * @param {number} group qq群号
     */
    serverInfo(msg, group) {
        RobotApiClass.sendGroupMsg(group, "正在查询内存中!");
        system.cmd("systeminfo", (exitcode, output) => {
            let totalRam = output.match(/Total Physical Memory:     ([\d,\s]+MB)/);
            let residueRam = output.match(/Available Physical Memory: ([\d,\s]+MB)/);
            msg = msg.replace(/{ram}/g, residueRam[1]);
            msg = msg.replace(/{tram}/g, totalRam[1]);
            let lxlv = lxl.version();
            let levelname = File.readFrom(".\\worlds\\Bedrock level\\levelname.txt");
            msg += `\n当前LXL版本:${lxlv.major}.${lxlv.minor}.${lxlv.revision}`;
            msg += `\n当前服务器版本:${mc.getBDSVersion()}`;
            msg += `\n当前存档名:${levelname}`;
            msg += `\n当前时间:${system.getTimeStr()}`;
            msg = "[" + config.get("serverName") + "][服务器状态]\n" + msg;
            RobotApiClass.sendGroupMsg(group, msg);
        });
    },
    /**
     * 绑定游戏名
     * @param {number} qq qq号
     * @param {string} gameName 游戏名
     * @param {number} group 群号
     */
    bind(qq, gameName, group) {
        let bindList = bindConfig.get("bind");
        let bindinfo = bindList[gameName];
        if (typeof bindinfo != "undefined") {
            RobotApiClass.GetMemberInfo(group, bindinfo, (status, result) => {
                if (status != 200) {
                    RobotApiClass.sendGroupMsg(group, [RobotApiClass.at(qq),RobotApiClass.text(`[${config.get("serverName")}]这个游戏名已被[${bindinfo}]绑定了!`)]);
                } else {
                    let msgUserName = bindinfo;
                    if (result.msg != "指定对象不存在") {
                        msgUserName = result.memberName;
                    }
                    RobotApiClass.sendGroupMsg(group, [RobotApiClass.at(qq),RobotApiClass.text(`[${config.get("serverName")}]这个游戏名已被[${msgUserName}]绑定了!`)]);
                }
            });
            return false;
        }
        //清除该账号已经绑定的
        let listobj = Object.keys(bindList);
        listobj.forEach(name => {
            if (bindList[name] == qq) {
                mc.runcmd(`whitelist remove "${name}"`);//删除旧的游戏白名单
                delete bindList[name];
            }
        });
        //绑定
        bindList[gameName] = qq;
        bindConfig.set("bind", bindList);
        mc.runcmd(`whitelist add "${gameName}"`);
        RobotApiClass.sendGroupMsg(group, [RobotApiClass.at(qq),RobotApiClass.text(`[${config.get("serverName")}][${gameName}] 绑定成功!`)]);
    },
    /**
     * 解除游戏名绑定
     * @param {string} gameName 游戏名
     * @param {number} group 群号
     */
    unbind(gameName, group) {
        let bindList = bindConfig.get("bind");
        let bindinfo = bindList[gameName];
        if (typeof bindinfo == "undefined") {
            RobotApiClass.sendGroupMsg(group, `[${config.get("serverName")}][${gameName}]还未被成员绑定!`);
            return false;
        }
        delete bindList[gameName];
        mc.runcmd(`whitelist remove "${gameName}"`);
        bindConfig.set("bind", bindList);
        RobotApiClass.sendGroupMsg(group, `[${config.get("serverName")}][${gameName}] 成功解除绑定!`);
    },
    /**
     * 解析url接口自定义配置
     * @param {Object} urlc 配置对象
     * @param {string} group 群号
     */
    url(urlc,group){
       if(urlc.method != "post" && urlc.method != "get"){
            RobotApiClass.sendGroupMsg(group, `[${config.get("serverName")}] 接口method错误只能 post/get 其中之一!`);
            return;
       }

       request(urlc.url,urlc.data,urlc.method).then(result=>{
            if(!websocketClass.isJSON(result)){
                RobotApiClass.sendGroupMsg(group, result);
                return;
                //不是json数据 直接返回 
            }
            result = JSON.parse(result);//进行json转对象
            let arrgather = [];
            let ArrayS = urlc.return.data;
            for(let index in ArrayS){
                if(ArrayS[index].type == "text"){
                    if(typeof ArrayS[index].msg != "undefined"){
                        arrgather.push(RobotApiClass.text(ArrayS[index].msg));
                        continue;
                    }
                    arrgather.push(RobotApiClass.text(strToobj(result,ArrayS[index].path)));
                }else if(ArrayS[index].type == "image"){
                    arrgather.push(RobotApiClass.image(strToobj(result,ArrayS[index].path)));
                }
            }
            RobotApiClass.sendGroupMsg(group, arrgather);
       })
       .catch(error=>{
            RobotApiClass.sendGroupMsg(group, `[${config.get("serverName")}] 接口请求失败/或者配置参数错误!请检查`);
       });

    }
}

PluginsClass.listen("onJoin", (pl) => {//进入服务器
    if (config.get("functionSwitch").InAndOutOfTip) {
        config.get("group").forEach(groupid => {
            RobotApiClass.sendGroupMsg(groupid, "玩家 " + pl.name + " 进入" + config.get("serverName") + "!");
        });
    }
});


PluginsClass.listen("onLeft", (pl) => {//退出服务器
    if (config.get("functionSwitch").InAndOutOfTip) {
        config.get("group").forEach(groupid => {
            RobotApiClass.sendGroupMsg(groupid, "玩家 " + pl.name + " 退出" + config.get("serverName") + "!");
        });
    }
});

PluginsClass.listen("onChat", (pl, msg) => {
    if (config.get("functionSwitch").ChatForward) {
        config.get("group").forEach(groupid => {
            RobotApiClass.sendGroupMsg(groupid, `[${config.get("serverName")}]<${pl.name}> ${msg}`);
        });
    }
});

PluginsClass.listen("onGroupMessage", (group, user, msg) => {
    //群聊
    let Limtgroup = config.get("group");
    let adminList = config.get("adminList");
    let regularList = config.get("regular");
    let isGroup = Limtgroup.filter(groupid => groupid == group.id);
    if (isGroup.length >= 1) {//对指定群进行操作
        regularList.forEach(strSe => {
            let RegularOject = new RegExp(strSe.se);
            if (strSe.type == "group" && RegularOject.test(msg.text)) {
                if (strSe.op && adminList.filter(va => user.id == va).length <= 0) return false;//是否管理员
                /* 执行指令 */
                if (typeof strSe.cmd != "undefined") {
                    //根据匹配的内容重组cmd字符
                    let NewCmd = strSe.cmd;
                    msg.text.replace(RegularOject, (...agexs) => {
                        for (let i = 1; i < (agexs.length - 2); i++) {
                            NewCmd = NewCmd.replace(`$${i}`, agexs[i]);
                        }
                    });
                    //进行其它操作
                    if (typeof strSe.result == "undefined" && typeof strSe.msg == "undefined") {
                        //不带任何返回结果
                        mc.runcmd(NewCmd);
                    } else if (typeof strSe.result == "undefined" && typeof strSe.msg != "undefined") {
                        //不带返回匹配格式  直接返回信息
                        let newMsg = strSe.msg;
                        mc.runcmd(NewCmd);
                        msg.text.replace(RegularOject, (...agexs) => {
                            for (let i = 1; i < (agexs.length - 2); i++) {
                                newMsg = newMsg.replace(`$${i}`, agexs[i]);
                            }
                        });
                        RobotApiClass.sendGroupMsg(group.id, [RobotApiClass.at(user.id),RobotApiClass.text(`[${config.get("serverName")}]${newMsg}`)]);
                    } else {
                        //带返回匹配格式
                        let cmds = mc.runcmdEx(NewCmd).output;//
                        let seObj = new RegExp(strSe.result, 'g');
                        let sendMsg = cmds.replace(seObj, (...ages) => {
                            let text = strSe.msg;
                            for (let i = 1; i < (ages.length - 2); i++) {
                                text = text.replace(`$${i}`, ages[i]);
                            }
                            return text;
                        });
                        RobotApiClass.sendGroupMsg(group.id, [RobotApiClass.at(user.id),RobotApiClass.text(`[${config.get("serverName")}]${sendMsg}`)]);
                    }
                } else if (typeof strSe.fun != "undefined") {
                    /* 调用函数 */
                    switch (strSe.fun) {
                        case "tellAll":
                            let msgText = msg.text.replace(new RegExp(strSe.se, 'g'), (...ages) => {
                                let text = strSe.msg;
                                for (let i = 1; i < (ages.length - 2); i++) {
                                    text = text.replace(`$${i}`, ages[i]);
                                }
                                return text;
                            });
                            msgText = msgText.replace(/{user.name}/g, user.name);
                            msgText = msgText.replace(/{user.id}/g, user.id);
                            msgText = msgText.replace(/{group.id}/g, group.id);
                            msgText = msgText.replace(/{group.name}/g, group.name);
                            funs.tellAll(msgText);
                            break;
                        case "serverInfo":
                            funs.serverInfo(strSe.msg, group.id);
                            break;
                        case "bind":
                            var result = srString(strSe.msg, msg.text, strSe.se);//替换msg 的 $1 ~
                            funs.bind(String(user.id), result, group.id);
                            break;
                        case "unbind":
                            var result = srString(strSe.msg, msg.text, strSe.se);
                            funs.unbind(result, group.id);
                            break;
                        case "transfer"://转账
                            var result = srString(strSe.msg, msg.text, strSe.se);
                            var pl = [];
                            pl[0] = selectGameName(user.id);
                            if (pl[0] == null) {//当前玩家未绑定
                                RobotApiClass.sendGroupMsg(group.id, [RobotApiClass.at(user.id),RobotApiClass.text(`[${config.get("serverName")}]你未绑定游戏名!无法使用该功能!`)]);
                                return;
                            }
                            pl[0] = data.name2xuid(pl[0]);//获取当前发信息玩家的xuid
                            //查询被艾特的玩家
                            var piText = msg.text.match(RegularOject);//获取正则的qq

                            pl[1] = selectGameName(piText[1]);
                            if (pl[1] == null) {//当前玩家未绑定
                                RobotApiClass.sendGroupMsg(group.id, [RobotApiClass.at(user.id),RobotApiClass.text(`[${config.get("serverName")}]目标玩家未绑定游戏名!无法对TA使用该功能!`)]);
                                return;
                            }
                            result = result.replace(/{bind.name}/g, pl[1]);//替换绑定的名称
                            pl[1] = data.name2xuid(pl[1]);//获取目标玩家的xuid
                            if (pl[1] == "") {
                                RobotApiClass.sendGroupMsg(group.id, [RobotApiClass.at(user.id),RobotApiClass.text(`[${config.get("serverName")}]目标玩家未进过服务器!无法对TA使用该功能!`)]);
                                return;
                            }
                            if (pl[0] == pl[1]) {
                                RobotApiClass.sendGroupMsg(group.id, [RobotApiClass.at(user.id),RobotApiClass.text(`[${config.get("serverName")}]你不能对自己发起转账!`)]);
                                return;
                            }
                            funs.transfer(pl[0], pl[1], Number(piText[2]), result, group.id);
                            break;
                        case "DeductMoney"://扣钱
                            var pl = '';
                            var result = srString(strSe.msg, msg.text, strSe.se);
                            var piText = msg.text.match(RegularOject);//获取正则的qq

                            pl = selectGameName(piText[1]);
                            if (pl == null) {//当前玩家未绑定
                                RobotApiClass.sendGroupMsg(group.id, [RobotApiClass.at(user.id),RobotApiClass.text(`[${config.get("serverName")}]目标玩家未绑定游戏名!无法对TA使用该功能!`)]);
                                return;
                            }
                            result = result.replace(/{bind.name}/g, pl);//替换绑定的名称
                            pl = data.name2xuid(pl);//获取目标玩家的xuid
                            if (pl == "") {
                                RobotApiClass.sendGroupMsg(group.id, [RobotApiClass.at(user.id),RobotApiClass.text(`[${config.get("serverName")}]目标玩家未进过服务器!无法对TA使用该功能!`)]);
                                return;
                            }
                            funs.DeductMoney(pl, Number(piText[2]), result, group.id);
                            break;
                        case "AddMoney"://加钱
                            var pl = '';
                            var result = srString(strSe.msg, msg.text, strSe.se);
                            var piText = msg.text.match(RegularOject);//获取正则的qq

                            pl = selectGameName(piText[1]);
                            if (pl == null) {//当前玩家未绑定
                                RobotApiClass.sendGroupMsg(group.id, [RobotApiClass.at(user.id),RobotApiClass.text(`[${config.get("serverName")}]目标玩家未绑定游戏名!无法对TA使用该功能!`)]);
                                return;
                            }
                            result = result.replace(/{bind.name}/g, pl);//替换绑定的名称
                            pl = data.name2xuid(pl);//获取目标玩家的xuid
                            if (pl == "") {
                                RobotApiClass.sendGroupMsg(group.id, [RobotApiClass.at(user.id),RobotApiClass.text(`[${config.get("serverName")}]目标玩家未进过服务器!无法对TA使用该功能!`)]);
                                return;
                            }
                            funs.AddMoney(pl, Number(piText[2]), result, group.id);
                            break;
                        case "TheBalanceOf"://查看余额
                            var result = srString(strSe.msg, msg.text, strSe.se);
                            var pl = '';
                            pl = selectGameName(user.id);
                            if (pl == null) {//当前玩家未绑定
                                RobotApiClass.sendGroupMsg(group.id, [RobotApiClass.at(user.id),RobotApiClass.text(`[${config.get("serverName")}]你未绑定游戏名!无法使用该功能!`)]);
                                return;
                            }
                            result = result.replace(/{bind.name}/g, pl);//替换绑定的名称
                            pl = data.name2xuid(pl);//获取当前发信息玩家的xuid
                            funs.TheBalanceOf(pl, result, group.id);
                            break;

                        case "url":
                            //解析url请求
                           
                           let urlType = strSe.msg;//获取配置类型
                           let urlc = urlConfig.get(urlType);
                           if(typeof urlc == "undefined"){
                                RobotApiClass.sendGroupMsg(group.id, [RobotApiClass.at(user.id),RobotApiClass.text(`[${config.get("serverName")}]该接口解析未配置!`)]);
                                return;
                           }
                            urlc.data = srString(urlc.data, msg.text, strSe.se);//解析正则的信息
                            funs.url(urlc,group.id);
                        break;
                    }

                } else {
                    colorLog("red", "[LXLRobot][正则扩展][" + config.get("serverName") + "]错误的配置指令");
                }
            }
        });
    }
});

PluginsClass.listen("onConsoleOutput", (cmd) => {
    let regularList = config.get("regular");
    regularList.forEach(strSe => {
        if (strSe.type == "cmd") {//过滤只执行cmd类型的
            let regexS = new RegExp(strSe.se);
            if (regexS.test(cmd)) {
                let msgs = cmd.replace(regexS, (...ages) => {
                    let text = strSe.msg;
                    for (let i = 1; i < (ages.length - 2); i++) {
                        text = text.replace(`$${i}`, ages[i]);
                    }
                    return text;
                });
                config.get("group").forEach(groupid => {
                    RobotApiClass.sendGroupMsg(groupid, msgs.replace(/[\s]/g, ''));
                });
            }
        }
    });

});

/* 监听成员 离群 和 被踢 */
PluginsClass.listen("onMemberLeaveEventKick", MembersLeave);
PluginsClass.listen("onMemberLeaveEventQuit", MembersLeave);

function MembersLeave(group, user) {
    let Limtgroup = config.get("group");
    let stray = config.get("stray");//获取离开的操作
    let isGroup = Limtgroup.filter(groupid => groupid == group.id);
    if (isGroup.length >= 1) {//对指定群进行操作
        stray.forEach(v => {
            if (v.type == "cmd") {
                let cmds = v.cmd;
                let bindList = bindConfig.get("bind");
                let listobj = Object.keys(bindList);
                listobj.forEach(name => {
                    if (bindList[name] == user.id) {
                        cmds = cmds.replace(/{bind.name}/g, name);
                        delete bindList[name];
                        RobotApiClass.sendGroupMsg(group.id, `[${config.get("serverName")}][${user.name}] 已离群自动解绑`);
                    }
                });
                bindConfig.set("bind", bindList);
                mc.runcmd(cmds);
            } else if (v.type == "group") {
                let msg = v.msg.replace(/{user.name}/g, user.name);
                msg = msg.replace(/[\s]/g, '');
                RobotApiClass.sendGroupMsg(group.id, `[${config.get("serverName")}]${msg}`);
            }
        });
    }
}


PluginsClass.listen("onMemberJoinRequestEvent", (group, user) => {
    let Limtgroup = config.get("group");
    let AddGroupAgreed = config.get("AddGroupAgreed");
    let isGroup = Limtgroup.filter(groupid => groupid == group.id);
    if (isGroup.length >= 1 && config.get("functionSwitch").AddGroupAgreed) {
        let black = AddGroupAgreed.blacklist.filter(v => v == user.id);
        if (black.length <= 0) {
            RobotApiClass.ProcessGroupOn(group.id, user.id, user.eventId);
        } else {
            RobotApiClass.ProcessGroupOn(group.id, user.id, user.eventId, 1, "你已经被管理员 加入黑名单,拒绝入群!");
            log(`[LXLRobot][正则插件] ${user.name} 已经在群申请黑名单 已自动拒绝入群!`);
        }
    }
});

PluginsClass.listen("onServerStarted", () => {
    log('[LXLRobot]正则插件v'+versions);
    if (config.get("functionSwitch").ChatForward) {
        config.get("group").forEach(groupid => {
            RobotApiClass.sendGroupMsg(groupid, [RobotApiClass.atall(),RobotApiClass.text(`[${config.get("serverName")}]服务器已启动!`)]);
        });
    }
});


/**
 * 
 * @param {string} msg 预定消息
 * @param {string} text 实际消息
 * @param {string} se 正则表达式
 * @returns {string} 替换好的信息
 */
function srString(msg, text, se) {
    let RegularOject = new RegExp(se);
    let gameName = msg;
    text.replace(RegularOject, (...ages) => {
        for (let i = 1; i < (ages.length - 2); i++) {
            gameName = gameName.replace(`$${i}`, ages[i]);
        }
    });
    return gameName;
}

/**
 * 
 * @param {number} qq 成员qq号
 * @returns {string|null} 成员绑定的玩家名
 */
function selectGameName(qq) {
    let gameName = '';
    let bindList = bindConfig.get("bind");
    let listobj = Object.keys(bindList);
    for (item in listobj) {
        if (bindList[listobj[item]] == qq) {
            gameName = listobj[item];
            return gameName;
        }
    }
    return null;
}


/**
 * 请求方法
 * @param {string} url 
 * @param {string} data 
 * @param {string} type   post | get
 */
function request(url,data,type = 'get'){
    return new Promise((resolve,reject)=>{
        if(type == "post"){
            network.httpPost(url,data,'application/x-www-form-urlencoded',(status,result)=>{
                if(status!=200){
                    reject();
                    return;
                }
                resolve(result);
            });
        }else{
            network.httpGet(url+'?'+data,(status,result)=>{
                if(status!=200){
                    reject();
                    return;
                }
                resolve(result);
            });
        }
    });
}

/**
 * 取值
 * @param {object} obj 对象
 * @param {string} str 数据连接
 * @returns 
 */
function strToobj(obj,str){
    str.split(".").forEach(v=>{
        obj = obj[v];
    });
    return obj;
}
